

<template>
  <div>
    <el-button class="butB_Sel" @click="printBtn()">打印</el-button>
    <el-button class="butB_Sel" @click="printBtn2()">打印2</el-button>
    <div class="app-container" id="printcons" >
      <div
      class="print"
        style="margin:auto; padding: 0px 20px; width: 950px; font-size: 14px"
      >
        <table

          border="0"
          width="100%"
          align="center"
          cellspacing="0"
          cellpadding="0"
          cellSpacing="0"
          cellPadding="0"
          bordercolor="#000000"
          style="border-collapse: collapse"
        >
          <thead>
            <tr style="line-height: 60px; text-align: center">
              <td colspan="9"  style="font-size: 26px;" class="titleB">长期医嘱单</td>
            </tr>
            <tr style="line-height: 40px">
              <td colspan="1">病区:{{ tabeldata.room }}</td>
              <td colspan="1">床号:{{ tabeldata.name }}</td>
              <td colspan="2">姓名:{{ tabeldata.member.name }}</td>
              <td colspan="1">
                性别:{{
                  tabeldata.member.gender == 1
                    ? "男"
                    : tabeldata.member.gender == 2
                    ? "女"
                    : "未知"
                }}&nbsp;
              </td>
              <td colspan="1">
                年龄:{{ tabeldata.member.age }}岁
              </td>
              <td colspan="2">住院号:{{ tabeldata.ipt_no }}</td>
            </tr>
            <tr style="height: 30px; text-align: center">
              <td colspan="2" style="border: 1px solid black">开始</td>

              <td rowspan="2" style="height: 30px; border: 1px solid black">
                长期医嘱
              </td>
              <td colspan="2" style="border: 1px solid black">签名</td>

              <td colspan="2" style="border: 1px solid black">停止</td>

              <td colspan="2" style="border: 1px solid black">签名</td>
            </tr>
            <tr style="height: 30px">
              <td style="" style="border: 1px solid black">日期</td>
              <td style="border: 1px solid black">时间</td>

              <td style="border: 1px solid black">医生</td>

              <td style="border: 1px solid black">护士</td>

              <td style="border: 1px solid black">日期</td>
              <td style="border: 1px solid black">时间</td>
              <td style="border: 1px solid black">医生</td>

              <td style="border: 1px solid black">护士</td>
            </tr>
          </thead>
          <tbody>
            <tr
              v-for="(item, index) in drug2"
              :key="index"
              :class="index%10==0?'page123':''"
              style="height: 30px; border: 1px solid black"
            >
              <td style="border: 1px solid black">
                {{ item.start_time.split(" ")[0] }}
              </td>
              <td style="border: 1px solid black">
                {{ item.start_time.split(" ")[1] }}
              </td>

              <td
                style="border: 1px solid black"
                :style="
                  item.advice_type == '0'
                    ? 'text-align: center;position: relative;'
                    : 'text-align: left;position: relative;'
                "
              >
                {{ item.business_name }}
                <div
                  :style="
                    item.id2 == '1'
                      ? 'position: absolute;right:10px;top:0px;height:100%;width:2px;background: #000000'
                      : ''
                  "
                ></div>
              </td>
              <td style="border: 1px solid black">
                {{ item.advice_doctor_name }}
              </td>

              <td style="border: 1px solid black">
                {{ item.execution_user_name }}
              </td>
              <td style="border: 1px solid black">
                {{
                  item.end_time.split(" ")[0] == "0000-00-00"
                    ? ""
                    : item.end_time.split(" ")[0]
                }}
              </td>
              <td style="border: 1px solid black">
                {{
                  item.end_time.split(" ")[1] == "00:00:00"
                    ? ""
                    : item.end_time.split(" ")[1]
                }}
              </td>

              <td style="border: 1px solid black">
                {{ item.stop_doctor_name }}
              </td>
              <td style="border: 1px solid black">
                {{ item.stop_nurse_name }}
              </td>
            </tr>
          </tbody>

          <tfoot  class="footer"   style="line-height:60px">

              <tr v-if="showTFoot">

                                 <td colspan="20" style="display:flex;" >当前是第<font tdata="PageNO" format="0" >##</font>页</span>/共<font tdata="PageCount" format="0" >##</font></span>页</td>

              </tr>
              <tr v-else style="line-height:60px">

                                 <td colspan="1"  style="display:flex;padding-bottom:20px;border:0" >&nbsp;{{drug2.length}}</td>
               </tr>
            </tfoot>
        </table>
      </div>
    </div>
  </div>
</template>
<script>
import { getdictIndex } from "@/api/register";
export default {
  props: ["yizhudata", "type"],
  data() {
    return {
      showTFoot: true,
      tabeldata: {
        name: "",
        room: "",
      },
      sourcelist: [],
      arrdata: [],
      drug2: [],
      dayin: false,
    };
  },

  mounted() {
    this.drug2 = [];
    this.yizhudata = JSON.parse(this.$route.query.yizhudata);
    this.tabeldata = this.yizhudata.info;
    console.log(this.yizhudata);
    this.tabeldata.room_nameA = this.tabeldata.room_name.split("/");
    this.tabeldata.room = this.tabeldata.room_nameA[1];
    this.tabeldata.name = this.tabeldata.room_nameA[3];
    this.tabeldata2 = this.yizhudata.advice;
    // 		if (this.tabeldata2.length<40) {
    // 	for (let i = 0; i < 40-this.tabeldata2.length; i++) {

    // 		this.tabeldata2.push({
    // 			advice_doctor: '',
    // 			advice_doctor_name: "",
    // 			business_name: "",
    // 			end_time: " ",
    // 			start_time: " ",
    // 			is_group:0,
    // 			stop_doctor_name: '',
    // 			stop_nurse_name: '',
    // 			specification:'',
    // 			advice_type:'0',
    // 			show_usage:'',
    // 			used_frqu:{
    // 				name:''
    // 			}
    // 		})

    // 	}
    // }
    this.arrdata = this.tabeldata2;
    for (let i = 0; i < this.tabeldata2.length; i++) {
      if (this.tabeldata2[i].advice_type == 2) {
        this.tabeldata2[i].id2 = "";
        var arr = {
          advice_doctor: "",
          advice_doctor_name: "··",
          business_name: this.tabeldata2[i].show_usage,
          end_time: "··",
          start_time: "··",
          advice_type: "0",
          is_group: this.tabeldata2[i].is_group,
          stop_doctor_name: "··",
          stop_nurse_name: "··",
          specification: "··",
          usage: "··",
          used_frqu: {
            name: "",
          },
        };
        this.arrdata.splice(i + 1, 0, arr);
        // tabeldata2
        // console.log(i)
      }
    }
    this.tabeldata2 = this.arrdata;
    console.log("this.tabeldata2", this.tabeldata2);
    this.drug2 = this.tabeldata2;
    // if (this.tabeldata2.length > 40) {
    //   var arr = this.tabeldata2;
    //   for (let i = 0; i < Math.ceil(arr.length / 40); i++) {
    //     this.drug2.push(arr.slice(i * 40, 40 * (i + 1)));
    //   }
    // } else {
    //   this.drug2.push(this.tabeldata2);
    //   console.log(this.drug2);
    // }
    // var aty = this.drug2[this.drug2.length - 1];
    // var num = 40 - parseInt(aty.length);
    // console.log(num);
    // if (num < 40) {
    //   for (let i = 0; i < num; i++) {
    //     this.drug2[this.drug2.length - 1].push({
    //       advice_doctor: "",
    //       advice_doctor_name: "",
    //       business_name: "",
    //       end_time: " ",
    //       start_time: " ",
    //       is_group: 0,
    //       stop_doctor_name: "",
    //       stop_nurse_name: "",
    //       specification: "",
    //       advice_type: "0",
    //       show_usage: "",
    //       used_frqu: {
    //         name: "",
    //       },
    //     });
    //   }
    // }
    this.tianjiaids2();
  },
  // watch: {
  //   yizhudata(n) {
  // 	console.log(n)
  // 	this.drug2=[]
  // 	this.tabeldata2=[]
  //     this.tabeldata = n.info;
  //     this.tabeldata.room_nameA = this.tabeldata.room_name.split("/");
  //     this.tabeldata.room = this.tabeldata.room_nameA[1];
  //     this.tabeldata.name = this.tabeldata.room_nameA[3];
  //     this.tabeldata2 = n.advice;
  //     this.arrdata = this.tabeldata2;
  //     for (let i = 0; i < this.tabeldata2.length; i++) {
  //       if (this.tabeldata2[i].advice_type == 2) {
  //         this.tabeldata2[i].id2 = "";
  //         var arr = {
  //           advice_doctor: "",
  //           advice_doctor_name: "··",
  //           business_name: this.tabeldata2[i].show_usage,
  //           end_time: "··",
  //           start_time: "··",
  //           advice_type: "0",
  //           is_group: this.tabeldata2[i].is_group,
  //           stop_doctor_name: "··",
  //           stop_nurse_name: "··",
  //           specification: "··",
  //           usage: "··",
  //           used_frqu: {
  //             name: "",
  //           },
  //         };
  //         this.arrdata.splice(i + 1, 0, arr);

  //       }
  //     }
  //     this.tabeldata2 = this.arrdata;
  //     if (this.tabeldata2.length > 40) {
  //       var arr = this.tabeldata2;
  //       for (let i = 0; i < Math.ceil(arr.length / 40); i++) {
  //         this.drug2.push(arr.slice(i*40, 40*(i+1)));
  //       }
  //       console.log(this.drug2);
  //     } else {
  //       this.drug2.push(this.tabeldata2);
  //     }
  //     var aty = this.drug2[this.drug2.length - 1];
  //     var num = 40 - parseInt(aty.length);

  //     if (num < 40) {
  //       for (let i = 0; i < num; i++) {
  //         this.drug2[this.drug2.length - 1].push({
  //           advice_doctor: "",
  //           advice_doctor_name: "",
  //           business_name: "",
  //           end_time: " ",
  //           start_time: " ",
  //           is_group: 0,
  //           stop_doctor_name: "",
  //           stop_nurse_name: "",
  //           specification: "",
  //           advice_type: "0",
  //           show_usage: "",
  //           used_frqu: {
  //             name: "",
  //           },
  //         });
  //       }
  //     }
  //     this.tianjiaids2();
  //   },
  // },
  methods: {
    tianjiaids2() {
      for (let j = 0; j < this.tabeldata2.length; j++) {
        if (
          this.tabeldata2[j].is_group != null &&
          this.tabeldata2[j].is_group != 0
        ) {
          var arr = [];
          for (let i = 0; i < this.tabeldata2.length; i++) {
            if (
              this.tabeldata2[i].is_group == this.tabeldata2[j].is_group &&
              this.tabeldata2[j].advice_type
            ) {
              arr.push(i);
            }
          }
          for (let i = 0; i < arr.length; i++) {
            this.tabeldata2[arr[i]].id2 = "1";
          }
        }
      }
    },
    getindex() {
      getdictIndex({ group_id: "40" }).then((res) => {
        let data = res.data;
        data.forEach((item, key) => {
          if (item.id == 40) {
            this.sourcelist = item.items;
          }
        });
      });
    },
    getpint() {
      this["_API"].getPrintReport({ id: this.id }).then((res) => {
        if (res.code == 200) {
          this.tabeldata = res.data;
          this.tabeldata.source = this.mapxing(this.tabeldata.source);
        }
      });
    },

    mapxing(num) {
      var art = "";
      this.sourcelist.map(function (value, i, array) {
        if (value.id == num) {
          art = value.name;
        }
      });
      console.log(art);
      return art;
    },
    printBtn(e) {
      this.dayin = true;
      this.showTFoot = false;
      setTimeout(() => {
        this.dayinfun();
      }, 200);
    },
    printBtn2(e) {
      this.CreateOneFormPage();
    },
    CreateOneFormPage() {
      this.LODOP = getLodop();
      this.LODOP.ADD_PRINT_TABLE(
        0,
        0,
        "100%",
        "100%",
        document.getElementById("printcons").innerHTML
      );
      this.LODOP.SET_PRINT_MODE("PRINT_PAGE_PERCENT", "Auto-Width");
      this.LODOP.SET_PRINT_STYLEA(0, "LinkedItem", -1);
      this.LODOP.PREVIEW();

    },
    dayinfun() {
      let subOutputRankPrint = document.getElementById("printcons");

      let newContent = subOutputRankPrint.innerHTML;
      let oldContent = document.body.innerHTML;
      document.body.innerHTML = newContent;
      window.print();
      window.location.reload();
      return false;
    },
    //去掉页眉和页脚
    remove_ie_header_and_footer() {
      var hkey_path;
      hkey_path =
        "HKEY_CURRENT_USER\\Software\\Microsoft\\Internet Explorer\\PageSetup\\";
      try {
        var RegWsh = new ActiveXObject("WScript.Shell");
        console.log("RegWsh", RegWsh);
        RegWsh.RegWrite(hkey_path + "header", "");
        RegWsh.RegWrite(hkey_path + "footer", "");
      } catch (e) {
        console.log("RegWsh1", e);
      }
    },
  },
};
</script>
<style media="print">
@media print {
  @page {
    size: auto;
    margin: 0cm 0cm 0cm 0cm;
  }
  .page123{
    page-break-before: left;
    /* page-break-after: always;
    page-break-inside: avoid; */
  }
  .titleB {
    padding-top: 50px;
  }
}
</style>
<style lang='scss' scoped>
#printcons >>> tr {
  height: 30px !important;
  padding: 20px 10px;
  margin: 0rem;
  text-align: center !important;
}
#printcons >>> td {
  width: 150px;
  height: 30px !important;
  height: 100%;
  /* border: 0.5px solid #000000; */
  padding: 0rem;
  margin: 0rem;
  text-align: center;
}
// .app-container{
//   width: 800px;
// }
</style>
